<?php
defined('JETEE_PATH') or exit();

/**
*项目函数库  thin与jetee模式公用
* @version 1.0.2 22:12 2019/9/4
*/

/**
 * 记录帐户变动
 * @param   int     $uid			哪个用户的帐户
 * @param   int     $id				操作关联id
 * @param   int   	$money			本金变动   必须已*100
 * @param   int   	$gold			本金变动   必须已*100
 * @param   int     $change_type    操作类型以数据库说明为主
 * @param   string  $change_desc    变动说明
 * @return  void
 */
function account_log($uid,$id,$money = 0,$gold = 0, $rank_points = 0, $pay_points = 0, $change_desc='', $change_type = 99){
	if(!$uid) return false;
	$user=db()->row('select money,gold_coin,rank_points,pay_points from '.C('DB_PREFIX').'user where uid='.$uid);
	if(!$user) return false;
	/* 插入帐户变动记录 */
	$account_log = array(
		'uid'       	=> $uid,
		'id'			=> $id,
		'money'    		=> $user['money']+$money,
		'gold_coin'  	=> $user['gold_coin']+$gold,
		'rank_points'   => $user['rank_points']+$rank_points,
		'pay_points'    => $user['pay_points']+$pay_points,
		'change_time'   => time(),
		'change_desc'   => $change_desc,
		'change_type'   => $change_type
	);
	if($aid=db('account_log')->add($account_log)){
		if(E('User')->updateUser(array('uid'=>$uid,'money'=>$user['money']+$money,'gold_coin'=>$user['gold_coin']+$gold,'rank_points'=>$user['rank_points']+$rank_points,'pay_points'=>$user['pay_points']+$pay_points))){
			return $aid;
		}
	}
	return false;
}
